optimize: reduce unnecessary function calls#5048
Open
ningmingxiao wants to merge 1 commit into
Open
Conversation
32becea to
4058db1
Compare
haytok
reviewed
Jul 7, 2026
Signed-off-by: ningmingxiao <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR targets the startup-time regression reported in #5047 by reducing repeated container label lookups during healthcheck setup and avoiding unnecessary task.Wait() work in detach mode.
Changes:
- Extend healthcheck timer APIs (
CreateTimer/StartTimer) to accept an already-fetched labels map, and update extraction logic to reuse it. - Update container start/run/unpause paths to pass cached labels and skip healthcheck setup when no healthcheck label is present.
- Adjust
nerdctl runflow to avoid callingtask.Wait()in detach mode (but currently introduces a wait/start ordering risk for non-detach).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/healthcheck/healthcheck_manager_linux.go | Reuses caller-provided labels to avoid repeated container.Labels() calls during healthcheck timer setup. |
| pkg/healthcheck/healthcheck_manager_windows.go | Updates stub signatures to match new healthcheck API. |
| pkg/healthcheck/healthcheck_manager_freebsd.go | Updates stub signatures to match new healthcheck API. |
| pkg/healthcheck/healthcheck_manager_darwin.go | Updates stub signatures to match new healthcheck API. |
| pkg/containerutil/containerutil.go | Passes cached labels into healthcheck setup and skips healthcheck work when not configured. |
| cmd/nerdctl/container/container_run.go | Skips task.Wait() for detach runs and passes cached labels into healthcheck setup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+295
to
+299
| if hcStr, ok := lab[labels.HealthCheck]; ok && hcStr != "" { | ||
| // If container has health checks configured, create and start systemd timer/service files. | ||
| if err := healthcheck.CreateTimer(ctx, container, cfg, nerdctlCmd, nerdctlArgs, lab); err != nil { | ||
| return fmt.Errorf("failed to create healthcheck timer: %w", err) | ||
| } |
Comment on lines
+503
to
+506
| statusC, err := task.Wait(ctx) | ||
| if err != nil { | ||
| return err | ||
| } |
Member
There was a problem hiding this comment.
Contributor
Author
There was a problem hiding this comment.
you can see
https://github.com/containerd/containerd/blob/v2.3.3/cmd/ctr/commands/run/run.go#L249
@haytok
here we don't need to wait container exited
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
reduce about 100ms
ref:#5047